package com.example.administrator.yuejian23.Activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.administrator.yuejian23.Bean.MyCollect;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.R;
import com.example.administrator.yuejian23.Retrofit.RetrofitService;
import com.example.administrator.yuejian23.adapter.UserGuanZhuAdapter;
import com.example.administrator.yuejian23.adapter.UserShaituAdapter;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/10/18.
 */

public class MyGuanZhuActivity extends Activity{
    private RecyclerView recyclerView;
    private Retrofit retrofit;
    private UserGuanZhuAdapter userGuanZhuAdapter;
    private List<MyCollect> myCollectList;
    private String User_Id;
    private Context context;
    private  int user_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_collect);
        User_Id=getIntent().getStringExtra("User_Id");
      /*  context= MyGuanZhuActivity.this;
        user_id = getApplication().getSharedPreferences("userInfo", Context.MODE_PRIVATE).getInt("user_id",0);*/
        recyclerView= (RecyclerView) findViewById(R.id.user_guanzhu_recyclerview);
        retrofit=new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RetrofitService services=retrofit.create(RetrofitService.class);
        retrofit2.Call<List<MyCollect>> call=services.getUserGuanzhu(User_Id);
        call.enqueue(new Callback<List<MyCollect>>() {
            @Override
            public void onResponse(Call<List<MyCollect>> call, Response<List<MyCollect>> response) {
                List<MyCollect> list=response.body();
                userGuanZhuAdapter=new UserGuanZhuAdapter(MyGuanZhuActivity.this,list);
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(MyGuanZhuActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(userGuanZhuAdapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<List<MyCollect>> call, Throwable t) {
                Toast.makeText(MyGuanZhuActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });
    }
}
